<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网易云</title>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
	</head>
	<body>
		<div id="app">
			<input type="text" v-model="query" @keyup.enter="serchMusic"/>
			<audio id="audioPlay" :src="musicUrl" autoplay="autoplay" loop controls="controls"></audio>
			<p v-for="(item,index) in musicList" >
				<button type="button" @click="playMusic(item.id)">播放</button>
				{{item.name}}
			</p>
		</div>
		
		<script type="text/javascript">
			var app = new Vue({
				el: "#app",
				data:{
					query:"",
					musicList:[],
					musicUrl:"http://m7.music.126.net/20201217170909/a725682c03bc618d3b067a2e28608e77/ymusic/ts/free/d37f5180192c6ee361e72c1978d242de.mp3",
				},
				methods:{
					serchMusic:function(){
						var that = this
						axios.get("https://autumnfish.cn/search?keywords="+this.query)
						.then(function(response){
							console.log(response);
							that.musicList = response.data.result.songs;
						},function(err){
							console.log(err);
						})
					},
					
					playMusic: function(musicId){
						var that = this
						axios.get("https://autumnfish.cn/song/url?id="+musicId)
						.then(function(response){
							console.log(response);
							console.log(response.data.data[0].url);
							that.musicUrl = response.data.data[0].url;
							var play = document.getElementById("audioPlay")
							play.play();
							
						},function(err){
							
						})
						
					}
					
				}
			})
		</script>
	</body>
</html>
